<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.ag.contactTree.*"%>
<%@page import="com.ag.zhh.vo.*"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title></title>
		<meta content="text/html; charset=UTF-8" http-equiv="content-type">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<link type="text/css" href="/ag/css/dialog/jquery.ui.all.css"
			rel="stylesheet" />
			<!-- <link rel="stylesheet" href="../jquery-treeview/jquery.treeview.css" /> -->
		<link rel="stylesheet" href="../zhh/css/utils.css" />
		
		<style type="text/css">

.validateTips {
	border: 0px solid transparent;
	padding: 0.3em;
	width: 95%
}

body {
	/*margin-top:120px;*/
	background-color: #dceffd;
	width:200%;
	margin:0px;
}
li{
list-style:none;
}

ul li ul
{
	display:none;
}
.deptli
{
	margin-left:-5px;
	padding-left:0px;
}
.contactli
{
	margin-left:5px;
	padding-left:0px;
}
.expandclose
{
	padding-top:8px;
	text-align:center;
	width:20px;
	height:20px;	
	font-weight:60;
	margin-right:-8px;
	
	margin-top:10px;
/*	background-color:#cccc99;*/
}
</style>
		<script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script>
		<script src="../jquery-treeview/lib/jquery.cookie.js"
			type="text/javascript"></script>
		<script src="../jquery-treeview/jquery.treeview.js"
			type="text/javascript"></script>
		<script type="text/javascript" src="../zhh/js/contact.js"></script>

		<script type="text/javascript">
  				<%--	var contextPath = "<%=path%>";--%>
		</script>

		<script src="/ag/zhh/js/party.js" type="text/javascript"></script>
		<script type="text/javascript" src="/ag/zhh/js/uploadFaxFile.js"></script>
		
		<!-- <script type="text/javascript" charset="UTF-8" src="/ag/zhh/js/JsonRpcClient.js" ></script> -->


		<!-- 
		<script src="/ag/zhh/js/call.js" type="text/javascript"></script>
		<script src="/ag/zhh/js/sendMessages.js" type="text/javascript"></script>
		<script src="/ag/zhh/js/sendFax.js" type="text/javascript"></script>
		 -->
		<script type="text/javascript" src="/ag/js/dialog/jquery.ui.core.js"></script>
		<script type="text/javascript" src="/ag/js/dialog/jquery.ui.widget.js"></script>
		<script type="text/javascript" src="/ag/js/dialog/jquery.ui.mouse.js"></script>
		<script type="text/javascript" src="/ag/js/dialog/jquery.ui.button.js"></script>
		<script type="text/javascript" src="/ag/js/dialog/jquery.ui.draggable.js"></script>
		<script type="text/javascript" src="/ag/js/dialog/jquery.ui.position.js"></script>
		<script type="text/javascript" src="/ag/js/dialog/jquery.ui.resizable.js"></script>
		<script type="text/javascript" src="/ag/js/dialog/jquery.ui.dialog.js"></script>
		<script type="text/javascript" src="/ag/js/dialog/jquery.effects.core.js"></script>
		<script type="text/javascript" src="/ag/css/dialog/jquery.bgiframe-2.1.1.js"></script>
<script type="text/javascript">
$(function(){

	$("#tongbu").click(function(){
		alert("同步");
			window.location.href="/ag/lwc/synchronism.action";
		});
});
</script>
	</head>
	<body>
		
		<div id="contactmenu2" style="">
			<table width="100%" border="0" bordercolor="#cccc99" cellpadding="0" cellspacing="0">
				<!-- 
				 <tr>
					<td align="center">
						<span id="myContactLink" style="font-size: 16;text-decoration: underline;">我的通信录</span>
					</td>
					<td align="center">
						<span id="myOAContactLink" style="font-size: 12">OA通信录</span>
					</td>
					<td align="center">
						<span id="telLink" style="font-size: 16;text-decoration: underline;">呼叫</span>
					</td>
					<td align="center">
						<span id="smsLink" style="font-size: 16;text-decoration: underline;">短信</span>
					</td> 
					<td align="center">
						<span id="faxLink" style="font-size: 16;text-decoration: underline;">传真</span>
					</td>
				
				</tr>
				

				<tr>
					<td colspan="4">
					<div>
						<img src="../zhh/images/Arrow1 Left.gif" onclick="showHideFrame(1)">
						<img src="../zhh/images/Arrow1 Right.gif" onclick="showHideFrame(-1)">
					</div>
					</td>
				</tr>
				 -->
			</table>
			<div id="deptType" style="height: 30px;display:none;">
				<div id="radio" style="padding-left: 15px; padding-top: 10px; align: center;">
				<%-- <%
						String deptType = (String)request.getAttribute("deptType");
						if(deptType == null){
							deptType = "all";
						}
						String treeType = (String) request.getAttribute("treeType");
						%>
				
				
				if (treeType != null && "0001".equals(treeType)) {
					%>
					
					<table  width="100%" border="0" bordercolor="#cccc99" style="font-size:12"><tr><td>应急部门:
					<input type="radio" name="udIfRadio" value="emergency" <%=deptType.equals("emergency")?"checked":"" %>></input>
					|</td><td>日常部门:
					<input type="radio" name="udIfRadio" value="general" <%=deptType.equals("general")?"checked":"" %>></input>
					|</td><td>所有部门:
					<input type="radio" name="udIfRadio" value="all" <%=deptType.equals("all")?"checked":"" %>></input>
					</td></tr></table><%
						}
					%>
				--%>	
				</div>
			</div>

			<table border="0" width="100%" bordercolor="blue">
				<tr>
					<td>
						<select id="treeTypeSelect">
							<c:forEach var='deptType' items='${deptTypes}' varStatus='status'>
								<option value='${deptType.dtId }' ${deptType.dtId==treeType?"selected":"" }>
									${deptType.dtName}
								</option>
							</c:forEach>
						</select>

					</td>
				
					<td align="right">
					<a id="tongbu" style="cursor:pointer;color:blue;">同步数据库</a>
					
					<%--
					以下不太清楚做什么的,注掉,国明
						--%>
						<%--<input type="text" id="text" class="input" size="12" maxlength="10">
						<span style="width: 20">&nbsp;</span>
						<input type="button" id="find" value="查询" class="button" />
						<input type="button" id="clear" value="清除" class="button"/>
					--%></td>
				</tr>
			</table>
		</div>

		<%--输出用户通信录 --%>
		<%!public void printLocalTree(UserDept node, ServletRequest request,ServletResponse response, JspWriter out, boolean isroot,boolean isclose) throws Exception
		{

		boolean setUl = false; // 是否已经输出了一次ul

	//	System.out.println("nodeId" + node.getNodeId());
		if (node != null)
		{
		UserDept dept =  node;
		
			out.println("<li class='deptli'>");
			if(dept.getTbUsers()!=null&&dept.getTbUsers().size()>0||dept.getTbUserDepts()!=null&&dept.getTbUserDepts().size()>0)
					out.println("<span class='expandclose'><img src='/ag/zhh/images/plus.gif'></img></span>");
			else if(dept.getTbDeptType()!=null&&!dept.getTbDeptType().getDtId().equals("0000"))
			{
				out.println("&nbsp;&nbsp;&nbsp;&nbsp;");
			}
			String tel = "telnone"; // 表示电话
			String phone = "phonenone"; // 手机
			String fax = "faxnone"; // 联系方式
			
			if (dept.getUdTel() != null&&dept.getUdTel().length()!=0)
				tel = dept.getUdTel();
			if (dept.getUdPhone() != null&&dept.getUdPhone().length()!=0)
				phone = dept.getUdPhone();
			if (dept.getUdFax() != null)
				fax = dept.getUdFax();
			String contact = tel + "," + phone + "," + fax;
			// 部门有联系方式
			if (dept.getUdTel() != null || dept.getUdPhone() != null)
			{	
				out.println("<input type='checkbox' name='"+contact+"' value='"+dept.getUdId()+"'>");
			}
			//部门没有联系方式
			else
			{
				out.println("<input type='hidden' name='"+contact+"' value='"+dept.getUdId()+"'>");
			}
			
			//输出部门名字
			//部门有子部门或下级部门
			if(dept.getTbUsers()!=null&&dept.getTbUsers().size()>0||dept.getTbUserDepts()!=null&&dept.getTbUserDepts().size()>0)
				out.println("<a href='#' class='expandclose2'>"+dept.getUdName()+"</a>");
			//部门没有子部门
			else
			{
				if(dept.getTbDeptType()==null||"0000".equals(dept.getTbDeptType().getDtId()))	 out.println("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='#' class='expandclose2'>"+dept.getUdName()+"</a>");
				else out.println("<a href='#' class='expandclose2'>"+dept.getUdName()+"</a>");
			} 
			
			//部门的联系人
				Set<UserDeptContact> contacts = node.getTbUsers();
				if (contacts != null && contacts.size() > 0)
				{
					// 判断是否已经输出<ul>

					if (!setUl)
					{
						out.println("<ul>");
						setUl = true;
					}
					for (UserDeptContact child : contacts)
					{
						String tel1 = "telnone"; // 表示电话
						String phone1 = "phonenone"; // 手机
						String fax1 = "faxnone"; // 联系方式
						String name = "";          //添加了姓名....zlw
						if (child.getUTel() != null&&child.getUTel().length()!=0)
							tel1 = child.getUTel();
						if (child.getUPhone() != null&&child.getUPhone().length()!=0)
							phone1 = child.getUPhone();
						if (child.getUFax() != null&&child.getUFax().length()!=0)
							fax1 = child.getUFax();
						if (child.getUName() !=null)
							name = child.getUName();
						String contact1 = tel1 + "," + phone1 + "," + fax1+ "," + name;    //添加了姓名....zlw
				//		System.out.println("Local 用户的联系方式：" + contact1);
						out.println("<li class='contactli'><input type='checkbox' value='"
										+ child.getUId()
										+ "' name="
										+ contact1
										+ "  /><a href='#' >"
										+ child.getUName() + "&nbsp;&nbsp;("+child.getUPhone()+")</a></li>");
					}

				}
				
				System.out.println(dept.getUdName()+"     \t子部门数目  "+dept.getTbUserDepts().size());
				
				// 子部门列表

				Set<UserDept> childrendept = node.getTbUserDepts();
				System.out.println(dept.getUdName()+"childlist的数目："+childrendept.size());
				if (childrendept.size() > 0)
				{
					if (!setUl)
					{
						out.println("<ul>");
						setUl = true;
					}
					for (UserDept cdept:childrendept)
					{
					//输出子部门
					System.out.println(cdept+"的A字段属性："+cdept.getA());
						if(cdept.getA()==null||cdept.getA().equals("0"))  printLocalTree(cdept, request, response, out, false,true);
					}

				}
				if (setUl)
				{
					out.println("</ul>");
				}
				out.println("</li>");
			
		}
	}%>

		<div style="margin-top:-20px;">
		<!-- 		<div id="contactTreecontrol" style="display:none;">
				<a href="?#">关闭所有结点</a> |
				<a href="?#">打开所有节点</a>
			</div> -->
	
			<ul id="contactTree">
				<%
					TreeNode treeRoot = null;
						Object treeRootTempObj = request.getAttribute("treeRoot");
						if (treeRootTempObj != null
								&& !treeRootTempObj.getClass().equals(String.class)) {
							treeRoot = (TreeNode) treeRootTempObj;
							//获取根节点,并转化为部门对象
							//if("0000".equals(treeType)) {
							//	printOATree(treeRoot, request, response, out);
							//}else {
								
								printLocalTree((UserDept)treeRoot.getBindData(), request, response, out,true,false);
							//}

						}
				%>
			</ul>
		</div>
		
		<div id="msgdialog" title="信息" style="display:none;">
			<ul id="mess"></ul>
		</div>
		<div id="smsdialog" title="编辑短信息" style="display:none;">
			<p class="validateTips"></p>
			<table border="0" width="100%">
				<tr>
					<td align="right" valign="top" width="40%">
						收信人：
					</td>
					<td>
						<select multiple="multiple" id="smsPerson" size="3">
						</select>
					</td>
				</tr>
				<tr>
					<td align="right" valign="top">
						短信息内容：
					</td>
					<td>
						<form action="#" id="form1">
							<textarea cols="35" rows="6" id="contend" name="contend"></textarea>
						</form>
					</td>
				</tr>
			</table>
		</div>
		
		<!-- 弹出的发送传真的窗口   -->
     <div id="sendFaxWindow">
                <table border='0' width='98%' height="98%" cellpadding="3" cellspacing="1" align="center" style="background-color: #1177bd">
                    <tr>
                        <td bgcolor="#ffffff">
                            <div id="userForm">
                                <table width="480px" align="center">
                                    <tbody id="selectArea">
                                        <tr>
                                            <td>
                                                <div style="margin-top: 10px">
                                                    <table width="460px" align="center">
                                                        <tr>
                                                          <td colspan="2">
                                                             <span class="span_n" style="color: #960;">接收人:（可以外加传真号码，用分号隔开即可，例如:  ;张三:123456）</span>
                                                           </td>
                                                        </tr>
                                                        <tr>
                                                          <td colspan="2">
                                                       		 <input type="text" id="faxPerson" name="faxPerson" value="" style="width: 280px"/>
                                                       	   </td>
                                                        </tr>
                                                         <tr>
														     <td colspan="2">
																<span class="span_n" style="color: #960;">传真文件：</span>
																<input type="button" name="upFile" id="upFile" value="添加 文件">&nbsp;
																<div id="upListDIV" style="display: none"></div>
														     </td>
														</tr>
                                                    </table>
                                                </div>
                                            </td>
                                            <td>
                                            </td>
                                        </tr>
                                    </tbody>
                                    <tr class="trtab">
                                        <td align="center">
                                            <input id='selOk' class="submit" type="Button" value="发送传真"/><span style="padding-left:20px"><input id='selCancel' class="submit" type="button" value="取消"/></span>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </td>
                    </tr>
                </table>
         </div>
         
         
         <input type="text" id="realfilenamehide" value="" style="display: none;"/>
         <input type="text" id="taskidhide" value="" style="display: none;"/>
          
         <div class="demo" style="display: none;">
				<div id="uploadFrame" title="添加传真文件">
					<iframe frameborder="0" name="uploadFrame" height="300"
						width="100%" scrolling="auto" src="/ag/zhh/upload.jsp" id="uploadFrame">
					</iframe>
		        </div>
         </div>
		
		
	<script type="text/javascript" src="/ag/zhh/js/test.js"></script>

	</body>
</html>